home *** CD-ROM | disk | FTP | other *** search
/ Amiga Format CD 51 / Amiga Format CD51 (2000-03-10)(Future Publishing)(GB)[!][issue 2000-04].iso / -in_the_mag- / pdselect / blizkick / modules / test.asm < prev    next >
Assembly Source File  |  2000-02-16  |  5KB  |  168 lines

  1. ; FILE: Source:modules/Test.ASM          REV: 5 --- Complex Module for BlizKick
  2.  
  3. ;
  4. ; Example BlizKick Module
  5. ; ~~~~~~~~~~~~~~~~~~~~~~~
  6. ; This code shows how to create complex BlizKick "Module".
  7. ; Should be quite self-explonary... (?)
  8. ;
  9. ; !CODE MUST BE FULLY PC-RELATIVE!
  10. ;
  11. ; Written by Harry Sintonen.
  12. ; This source code is Public Domain.
  13. ;
  14.  
  15.     incdir    "include:"
  16.     include    "exec/types.i"
  17.     include    "exec/libraries.i"
  18.     include    "exec/initializers.i"
  19.  
  20.     include    "exec/execbase.i"
  21.  
  22.     include    "blizkickmodule.i"    ; Some required...
  23.  
  24.  
  25. MYLIB_VERSION    EQU    1
  26. MYLIB_REVISION    EQU    2
  27.  
  28.  
  29.     STRUCTURE mylib,LIB_SIZE
  30.     APTR    ml_ExecBase
  31.     LABEL    mylib_SIZEOF
  32.  
  33.  
  34.     SECTION    LIBRARYMODULE,CODE
  35. _DUMMY_LABEL
  36.  BK_MODA BKMF_SingleMode,_end,(RTF_COLDSTART)<<24+30<<16+NT_LIBRARY<<8+11,_name,_idstr,mylib_SIZEOF,_funcs,_is,_init
  37.  
  38. ; SINGLE MODE, COLDSTART module, requires KS V30.x or better,
  39. ; module type NT_LIBRARY, priority 11.
  40.  
  41.     BK_INITFUNCS _funcs
  42.     ;------ system interface functions
  43.     BK_FUNC    my_LIB_OPEN
  44.     BK_FUNC    my_LIB_CLOSE
  45.     BK_FUNC    my_LIB_EXPUNGE
  46.     BK_FUNC    my_LIB_NULL
  47.     ;------ libraries definitions
  48.     BK_FUNC    my_GetVBR
  49.     BK_FUNC    my_SetVBR
  50.     BK_ENDFUNCS
  51.  
  52.    ; The data table initializes static data structures.  The format is specified in
  53.    ; exec/InitStruct routine's manual pages.  The INITBYTE/INITWORD/INITLONG routines are
  54.    ; in the file "exec/initializers.i".  The first argument is the offset from the library
  55.    ; base for this byte/word/long.  The second argument is the value to put in that cell.
  56.    ; The table is null terminated.
  57.  
  58. _is    INITBYTE    LN_TYPE,NT_LIBRARY
  59. ;;    INITLONG    LN_NAME,_name                ; No relocs!
  60.     INITBYTE    LIB_FLAGS,LIBF_SUMUSED!LIBF_CHANGED
  61.     INITWORD    LIB_VERSION,MYLIB_VERSION
  62.     INITWORD    LIB_REVISION,MYLIB_REVISION
  63. ;;    INITLONG    LIB_IDSTRING,_idstr            ; - "" -
  64.     dc.l   0
  65.  
  66. ; This routine gets called after the library has been allocated.  The library pointer is
  67. ; in D0.  The segment list is in A0.  If it returns non-zero then the library will be
  68. ; linked into the library list.
  69. ;
  70. _init    movem.l    a5/a6,-(sp)
  71.     move.l    d0,a5
  72.     move.l    a6,(ml_ExecBase,a5)
  73.  
  74.     lea    (_name,pc),a0
  75.     move.l    a0,(LN_NAME,a5)
  76.     lea    (_idstr,pc),a0
  77.     move.l    a0,(LIB_IDSTRING,a5)
  78.  
  79.     move.l    a5,d0
  80.     movem.l    (sp)+,a5/a6
  81.     rts
  82.  
  83. ;------------------------------------------------------------------------------------------
  84. ; here begins the system interface commands.  When the user calls OpenLibrary/CloseLibrary/
  85. ; RemoveLibrary, this eventually gets translated into a call to the following routines
  86. ; (Open/Close/Expunge).  Exec has already put our library pointer in A6 for us.  Exec has
  87. ; turned off task switching while in these routines (via Forbid/Permit), so we should not
  88. ; take too long in them.
  89. ;------------------------------------------------------------------------------------------
  90.  
  91.  
  92.    ; Open returns the library pointer in d0 if the open was successful.  If the open failed
  93.    ; then null is returned.  It might fail if we allocated memory on each open, or if only
  94.    ; open application could have the library open at a time...
  95.  
  96. my_LIB_OPEN
  97.     ; ( libptr:a6, version:d0 )
  98.     tst.w    (LIB_OPENCNT,a6)
  99.     beq.b    .open
  100. .done    move.l    a6,d0
  101.     rts
  102. .open    addq.w    #1,(LIB_OPENCNT,a6)
  103.     bra.b    .done
  104.  
  105.    ; There are two different things that might be returned from the Close routine.  If the
  106.    ; library is no longer open and there is a delayed expunge then Close should return the
  107.    ; segment list (as given to Init).  Otherwise close should return NULL.
  108.  
  109. my_LIB_CLOSE
  110.  
  111.    ; There are two different things that might be returned from the Expunge routine.  If
  112.    ; the library is no longer open then Expunge should return the segment list (as given
  113.    ; to Init).  Otherwise Expunge should set the delayed expunge flag and return NULL.
  114.    ;
  115.    ; One other important note: because Expunge is called from the memory allocator, it may
  116.    ; NEVER Wait() or otherwise take long time to complete.
  117.  
  118. my_LIB_EXPUNGE
  119. my_LIB_NULL
  120.     moveq    #0,d0
  121.     rts
  122.  
  123.    ; Functions:
  124.  
  125.  
  126. ; OUT: d0=vbr or zero if no vbr
  127. my_GetVBR
  128.     movem.l    a5/a6,-(sp)
  129.     move.l    (ml_ExecBase,a6),a6
  130.     moveq    #0,d0
  131.     btst    #AFB_68010,(AttnFlags+1,a6)
  132.     beq.b    .novbr
  133.     lea    (.getvbr,pc),a5
  134.     jsr    (-$1E,a6)        ;call Supervisor
  135. .novbr    tst.l    d0
  136.     movem.l    (sp)+,a5/a6
  137.     rts
  138. .getvbr    movec.l    vbr,d0
  139.     rte
  140.  
  141.  
  142. ;  IN: a0=new vbr, not set if no vbr
  143. ; OUT: d0=old vbr, always zero if no vbr
  144. my_SetVBR
  145.     movem.l    a5/a6,-(sp)
  146.     bsr.b    my_GetVBR
  147.     move.l    (ml_ExecBase,a6),a6
  148.     btst    #AFB_68010,(AttnFlags+1,a6)
  149.     beq.b    .novbr
  150.     lea    (.setvbr,pc),a5
  151.     jsr    (-$1E,a6)        ;call Supervisor
  152. .novbr    tst.l    d0
  153.     movem.l    (sp)+,a5/a6
  154.     rts
  155. .setvbr    movec.l    a0,vbr
  156.     rte
  157.  
  158.  
  159. _name    dc.b    'testmodule.library',0
  160. _idstr    dc.b    'testmodule.library 1.2 (26.2.97)',0
  161.     CNOP    0,2
  162. _end
  163.  
  164.  
  165.     SECTION    VERSION,DATA
  166.  
  167.     dc.b    '$VER: testmodule.library_MODULE 1.2 (26.2.97)',0
  168.